package com.wujilin.okra.adapter;

import android.content.Context;
import android.database.Cursor;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.TextView;

import com.wujilin.okra.Okra;
import com.wujilin.okra.R;
import com.wujilin.okra.database.ModelCursor;
import com.wujilin.okra.model.Model;

public class ArchiveListAdapter extends CursorAdapter {
	private ModelCursor cursor;
	
	public ArchiveListAdapter(Context context, ModelCursor cursor) {
		super(context, cursor, 0);
		this.cursor = cursor;
	}

	@Override
	public View newView(Context context, Cursor cursor, ViewGroup parent) {
		return Okra.getLayoutInflater(context).inflate(R.layout.list_item_archive, parent, false);
	}

	@Override
	public void bindView(View view, Context context, Cursor cursor) {
		TextView titleText = (TextView) view.findViewById(R.id.archive_title);
		TextView countText = (TextView) view.findViewById(R.id.archive_count);
		
		Model archive = this.cursor.getModel();
		String title = archive.getString("title");
		String count = archive.getString("count");
		titleText.setText(title);
		countText.setText(count);
	}
}
